package com.hadoop.demo.mapreduce.flowcount;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * =================================
 * <p>
 * Created by cjj on 18-10-8.
 * <p>
 * 描述: 流量信息对象 包括手机号，上行流量、下行流量和总流量
 */

public class FlowBean implements Writable {

    private String phoneNumber;

    //单位（b）
    private long up_flow;

    private long down_flow;

    private long sum_flow;

    //反序列化时需要使用反射，需要一个空的构造方法
    public FlowBean() {
    }

    //方便数据初始化
    public FlowBean(String phoneNumber, long up_flow, long down_flow) {
        this.phoneNumber = phoneNumber;
        this.up_flow = up_flow;
        this.down_flow = down_flow;
        this.sum_flow = up_flow + down_flow;
    }

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(phoneNumber);
        dataOutput.writeLong(up_flow);
        dataOutput.writeLong(down_flow);
        dataOutput.writeLong(sum_flow);

    }

    public void readFields(DataInput dataInput) throws IOException {
        phoneNumber = dataInput.readUTF();
        up_flow = dataInput.readLong();
        down_flow = dataInput.readLong();
        sum_flow = dataInput.readLong();

    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public long getUp_flow() {
        return up_flow;
    }

    public void setUp_flow(long up_flow) {
        this.up_flow = up_flow;
    }

    public long getDown_flow() {
        return down_flow;
    }

    public void setDown_flow(long down_flow) {
        this.down_flow = down_flow;
    }

    public long getSum_flow() {
        return sum_flow;
    }

    public void setSum_flow(long sum_flow) {
        this.sum_flow = sum_flow;
    }

    @Override
    public String toString() {
        return "FlowBean{" +
                ", up_flow=" + up_flow +
                ", down_flow=" + down_flow +
                ", sum_flow=" + sum_flow +
                '}';
    }
}
